package cn.com.nes.site.service.system.user;

import cn.com.nes.site.entity.bo.user.PushCallCenterUserInfoBO;
import cn.com.nes.site.entity.vo.user.PushUserInfoVO;
import cn.hutool.core.util.ObjectUtil;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 推送修改用户账号信息
 *
 * @Author: ShenWei
 * @Date: 2024/05/24/15:30
 */
@Service("pushUpdateUserInfoService")
public class PushUpdateUserInfoService extends PushUserInfoService {

    @Override
    public Integer getPushType() {
        return PushUserInfoVO.PUSH_TYPE_UPDATE;
    }

    @Override
    public void pushUserInfo(Map<String, Boolean> checkResult) throws Exception {
        callCenterUserId = ObjectUtil.isNotNull(userInfo.getCallCenterUserId()) ? String.valueOf(userInfo.getCallCenterUserId()) : null;

        // 如果需要绑定易修
        if (checkResult.get("pushEasyRepair")) {
            bindEasyRepairAccount();
        }

        // 如果需要解绑易修 = 不需要绑定易修 && 绑定过易修
        if (!checkResult.get("pushEasyRepair") && ObjectUtil.isNotNull(userInfo.getEasyRepairUserId())) {
            unBindEasyRepairAccount();
        }

        // 如果需要绑定长效管护
        if (checkResult.get("pushCallCenter")) {
            // 如果绑定过长效管护
            if (ObjectUtil.isNotNull(callCenterUserId)) {
                // 修改长效管护账号
                PushCallCenterUserInfoBO callCenterUserInfoBo = new PushCallCenterUserInfoBO();
                callCenterUserInfoBo.setName(userInfo.getNickName());
                callCenterUserInfoBo.setAccount(userInfo.getUsername());
                callCenterUserInfoBo.setPassword("CC_" + userInfo.getPhone());
                callCenterUserInfoBo.setCompanyId(Long.valueOf(vo.getCallCenterCompanyId()));
                callCenterUserInfoBo.setAgentUserId(uuid);
                callCenterUserInfoBo.setErUserId(easyRepairUserId);
                callCenterUserInfoBo.setUserType(userType);
                callCenterUserInfoBo.setPhone(userInfo.getPhone());
                callCenterUserInfoBo.setUserId(Long.valueOf(callCenterUserId));
                callCenterService.updateCallCenterUser(callCenterUserInfoBo);
            } else {
                // 如果没绑定过长效管护
                bindCallCenterAccount();
            }
        }
    }
}
